//引入路径插件
const path = require('path')
//引入自动创建html插件
const HTMLWebpackPlugin = require('html-webpack-plugin')
//引入打包前清空插件
const { CleanWebpackPlugin } = require('clean-webpack-plugin')

module.exports = {
  mode: 'development',
  entry: './src/index.ts',
  output: {
    path: path.resolve(__dirname,'dist'),
    filename: 'bundle.js',
  },
  // environment: {
  //   arrowFunction: false
  // }, 是否使用箭头函数
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              presets: [
                [
                  // 指定环境插件
                  '@babel/preset-env',
                  // 配置信息
                  {
                    targets: {
                      "chrome": '86'
                    },
                    "corejs": '3',
                    "useBuiltIns": 'usage' //按需加载
                  }
                ]
              ]
            }
          },
          'ts-loader', //下面的先执行
        ],
        exclude: /node_modules/
      },
      {
        test: /\.less$/,
        use: [
          "style-loader",
          "css-loader",
          {
            loader: "postcss-loader",
            options: {
              postcssOptions: {
                plugins: [
                  [
                    "postcss-preset-env",
                    {
                      browsers: 'last 2 versions'
                    },
                  ],
                ]
              }
            }
          },
          "less-loader"
        ],
        exclude: /node_modules/
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HTMLWebpackPlugin({
      template: './src/index.html'
    }),

  ],
  resolve: {
    extensions: ['.ts','.js']
  }
}